<template>
  <div class="user-size">
    <div class="box">
      <div class="user-size-item" v-for="item in list" :key="item.id">
        <div class="user">
          <span class="name">{{item.name}} <i v-if="item.isDefault" class="van-hairline--surround">默认</i></span>
          <Icon name="edit" />
        </div>
        <ul class="info">
          <li><span>性别</span><span>{{item.gender}}</span></li>
          <li><span>身高(cm)</span><span>{{item.height}}</span></li>
          <li><span>体重(kg)</span><span>{{item.bodyWeight}}</span></li>
          <li><span>肩宽(cm)</span><span>{{item.shoulderWidth}}</span></li>
          <li><span>胸围(cm)</span><span>{{item.chestCircumference}}</span></li>
          <li><span>臀围(cm)</span><span>{{item.waistCircumference}}</span></li>
          <li><span>脚围(cm)</span><span>{{item.hips}}</span></li>
        </ul>
        <div class="line van-hairline--bottom"></div>
      </div>
    </div>
    <div class="bottom">
      <Button v-if="list.length" @click="save()" class="button" type="primary" block>保存</Button>
    </div>
  </div>
</template>

<script>
import { Icon, Button, Toast } from 'vant'
export default {
  name: 'UserSize',
  components: { Icon, Button },
  data () {
    return {
      list: []
    }
  },
  async created () {
    await Toast.loading('正在加载')
    const { data } = await this.$http.get('/user/size')
    console.log(data)
    this.list = data.result
    Toast.clear()
  },
  methods: {
    async save () {
      await Toast.loading('正在保存')
      await this.$http.post('/user/size')
      await Toast.success('保存成功')
      window.setTimeout(() => {
        Toast.clear()
      }, 500)
    }
  }
}
</script>

<style scoped lang='less'>
.bottom {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: 10px;
  padding-right: 10px;
  height: 60px;
  background: #f8f8f8;
  .button {
    height: 40px;
    line-height: 40px;
    border-radius: 20px;
    margin: 10px 0;
  }
}
.user-size {
  padding-bottom: 70px;
  .box {
    background: #fff;
    border-radius: 4px;
    .user-size-item {
      padding: 15px 15px 0 15px;
      .user {
        display: flex;
        justify-content: space-between;
        .name {
          i {
            font-style: normal;
            font-size: 12px;
            color: #27ba9b;
            padding: 3px 3px 1px;
            line-height: 1;
            &::after {
              border-color: #27ba9b;
              border-radius: 2px;
            }
          }
        }
      }
      .info {
        display: flex;
        flex-wrap: wrap;
        font-size: 12px;
        line-height: 24px;
        li {
          width: 50%;
          display: flex;
          &:first-child {
            width: 100%;
            margin-top: 5px;
          }
          span {
            color: #666;
            &:first-child {
              width: 60px;
              color: #999;
            }
          }
        }
      }
      .line {
        padding-top: 10px;
      }
    }
  }
}
</style>
